gh-138580: add sys.float_info.iec_60559 boolean flag#138811
gh-138580: add sys.float_info.iec_60559 boolean flag#138811vstinner merged 15 commits intopython:mainfrom
Conversation
This value indicating support the IEC 60559 floating-point standard (the Annex F of C99). If enabled, the float type characteristics matches the IEC 60559 double format and exceptional cases for the math's functions follow to the section F.10 of the C99 standard.
|
I think it would be better if the field was in uppercase but I don't know if we have many other cases like that. |
This will be inconsistent wrt the rest (other field names are also come from macros). |
Co-authored-by: Victor Stinner <vstinner@python.org>
|
I'm thinking if it does make sense to mention this flag in cmath docs. We could say that:
|
|
@picnixz @serhiy-storchaka: What do you think of this change? |
|
I am not sure what is the best place for this constant. What do @mdickinson and @tim-one think about this? Other options are discussed in the issue. |
|
I'm not really comfortable with |
I think, this flag should rather describe conformance with the IEEE 754 / IEC 60559. |
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
|
Lets try to make some progress here.
@serhiy-storchaka, other options so far:
(1) or (2) don't make any sense, as the flag is not C-specific at all. So, (3) is only option. But the sys namespace is already big. And the new flag logically fits float_info: it offers some additional information about float type. Maybe we should rename this flag to sys.float_info.iec_60559? Other fields in this named tuple also have no strict binding to the C standard. Floating-point numbers in C are defined by same model as in the IEC 60559, i.e. have radix ( |
I still support this option ( |
@mdickinson and @tim-one didn't reply. Would you be ok with |
|
@serhiy-storchaka, see #145633 (comment). It looks like the IMO, we only have to decide: where in the sys module put this flag? |
|
Maybe open a DPO thread? |
Reformat also the doc to fit into 80 columns.
|
I decided to merge the change adding Since |
|
Build info on CI runs on this PR:
So iec_60559 is only true on Ubuntu CI. |
|
Yes, it looks adoption of the standard is poor as before. @vstinner, maybe it does make sense to revert this pr. Certainly, this flag can't be used for the |
|
I also looked at buildbots. iec_60559=True:
iec_60559=False:
Note: Some buildbots didn't run yet with the new iec_60559 attribute (I restarted the buildbot server this morning, it was stuck for an unknown reason). Some buildbots don't dump |
Why? It remains useful in the platforms where it's true, no?
Well, that's another issue. |
|
I built Python with clang 21.1.8 on my Fedora 43 with glibc 2.42-10: That's surprising because https://clang.llvm.org/c_status.html says about "C99 implementation status" that "Clang does not define
/* glibc's intent is to support the IEC 559 math functionality, real
and complex. If the GCC (4.9 and later) predefined macros
specifying compiler intent are available, use them to determine
whether the overall intent is to support these features; otherwise,
presume an older compiler has intent to support these features and
define these macros by default. */
#ifdef __GCC_IEC_559
# if __GCC_IEC_559 > 0
# define __STDC_IEC_559__ 1
# define __STDC_IEC_60559_BFP__ 201404L
# endif
#else
# define __STDC_IEC_559__ 1
# define __STDC_IEC_60559_BFP__ 201404L
#endif |
That's essentially linux and glibc with "intent is to support" ("An implementation that defines STDC_IEC_559 shall conform to the specifications in this annex." - this is not about best wishes, right?). The rest looks same as 20+ years ago :(, quite disappointing for me.
Yes, at least we can fill bugreports, when it's enabled and things goes wrong. The cons is that this not useful in the test suite. |
This value indicating support the IEC 60559 floating-point standard (specified by the Annex F of C99, for C language). If enabled, the float type characteristics matches the IEC 60559 double format and exceptional cases for the math's functions follow to the section F.10 of the C99 standard.
📚 Documentation preview 📚: https://cpython-previews--138811.org.readthedocs.build/
https://cpython-previews--138811.org.readthedocs.build/en/138811/library/sys.html#sys.float_info
https://cpython-previews--138811.org.readthedocs.build/en/138811/library/math.html#math.nan